from keras.preprocessing import image
import numpy as np
from keras.models import load_model
import keras.backend as K
import os
import matplotlib.pyplot as plt
import cv2 as cv

def tanh10(x):
        return K.tanh(10*x)

img_path = "D:/facial/premiere/jpg/FaceCapture0145.jpg"

def read_vgg():
        img = image.load_img(img_path, target_size=(224,224))
        x = image.img_to_array(img)
        x = np.expand_dims(x, axis=0)
        # x = preprocess_input(x)
        return x

def read_res():
        img=cv.imread(img_path)
        im=cv.resize(img,(224,224))
        x=np.array(im)#resnet用的
        x = np.expand_dims(x, axis=0)
        im=im.swapaxes(0,1)#resnet用的
        x=np.array(x)
        x=x.swapaxes(1,3)
        return x

x=read_res()
# x=read_vgg()
model = load_model('my_model -res_2000.h5') 
np.set_printoptions(precision=2)
preds = model.predict(x)
preds=preds.T
np.savetxt("test.txt",preds,fmt="%.02f")
name="test.txt"
os.rename(name,"test.csv")
print(preds)


